/*
 * npi.cpp - a sample xlisp extension module 
 */

/* Load this library with the command:

   (load-library "ndi.dll")

   You should then be able to invoke the my-add function:

   (my-add 2 3) ==> 5
         
*/

#include "xlisp.h"

#ifdef _WIN32
#	ifdef xlispndi_EXPORTS
#		define WIN_DLL_API __declspec(dllexport)
#	else
#		define WIN_DLL_API __declspec(dllimport)
#	endif
#else
#	define WIN_DLL_API
#endif

/* prototypes */
static xlValue ndi_add(void);
static xlValue ndi_dir(void);
static xlValue ndi_sizeof(void);

/* initialize - the dll initialization function */
extern "C" int WIN_DLL_API 
initialize(void)
{
	xlSubr((char *)"NDI-ADD", ndi_add);
	xlSubr((char *)"NDI-DIR", ndi_dir);
	xlSubr((char *)"NDI-SIZEOF", ndi_sizeof);
    return TRUE;
}

/// myadd - my add function
static xlValue 
ndi_add(void)
{
    xlFIXTYPE arg1, arg2;
    
    /* parse the argument list */
    xlVal = xlGetArgFixnum(); arg1 = xlGetFixnum(xlVal);
    xlVal = xlGetArgFixnum(); arg2 = xlGetFixnum(xlVal);
    xlLastArg();

    /* return the result of adding the two arguments */
    return xlMakeFixnum(arg1 + arg2);
}

static xlValue 
ndi_dir(void)
{
    xlLastArg();
    return xlMakeFixnum(sizeof(xlValue));
}

static xlValue 
ndi_sizeof(void)
{
    xlValue last, next;

    xlLastArg(); /* no arguments expected */

#if 0
    /* initialize the list */
    xlVal = xlNil;
	
	/* add each argument to the list */
    if (xlMoreArgsP()) {
        xlVal = last = xlCons(xlNextArg(),xlNil);
        while (xlMoreArgsP()) {
            next = xlCons(xlNextArg(),xlNil);
            xlSetCdr(last,next);
            last = next;
        }
    }
#endif

	xlVal = last = xlCons(xlCons(xlMakeCString("int"), xlCons(xlMakeFixnum(sizeof(int)), xlNil)), xlNil);

	next = xlCons(xlCons(xlMakeCString("long int"), xlCons(xlMakeFixnum(sizeof(long int)), xlNil)), xlNil);
	xlSetCdr(last,next);
	last = next;

	next = xlCons(xlCons(xlMakeCString("double"), xlCons(xlMakeFixnum(sizeof(double)), xlNil)), xlNil);
	xlSetCdr(last,next);
	last = next;

	next = xlCons(xlCons(xlMakeCString("long long int"), xlCons(xlMakeFixnum(sizeof(long long int)), xlNil)), xlNil);
	xlSetCdr(last,next);
	last = next;

	next = xlCons(xlCons(xlMakeCString("void *"), xlCons(xlMakeFixnum(sizeof(void *)), xlNil)), xlNil);
	xlSetCdr(last,next);
	last = next;

    /* return the list */
    return xlVal;
}

// Local Variables:
// mode: c
// c-basic-offset: 4
// tab-width: 4
// End:
